﻿//
//  THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
//  PURPOSE.
//
//  License: GNU Lesser General Public License (LGPLv3)
//
//  Email: alaabenfatma@yahoo.fr
//
//  Copyright (C) Alaa Ben Fatma, 2016-2017. 

namespace CharmNotification
{
   
    using System;
    using System.Drawing;
    using System.Media;
    using System.Windows.Forms;

    using CharmNotification.Properties;

    internal partial class NotificationHost : Form
    {
        private int x = 1;

        public NotificationHost(
            int Duration, 
            bool PlayTone,
            string Title, 
            string Text, 
            Image Icon, 
            Color Color1, 
            Color Color2, 
            Color TitleColor, 
            Color TextColor)
        {
            InitializeComponent();
            this.LeftSide.BackColor = Color1;
            this.RightSide.BackColor = Color2;
            this.Title.Text = Title;
            this.Message.Text = Text;
            this.pictureBox1.Image = Icon;
            this.Title.ForeColor = TitleColor;
            this.Message.ForeColor = TextColor;
            this.ShowInTaskbar = false;
            this.ClosingTimer.Interval = Duration;
            this.Playtn = PlayTone;
        }
        bool Playtn = true;
        private void ClosingTimer_Tick(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Notification_Load(object sender, EventArgs e)
        {
            this.Styler.Start();
            if (this.Playtn)
            {
                var player = new SoundPlayer(Resources.iPhone_tone);
                player.Play();
            }

            this.ClosingTimer.Start();
        }

        private void Styler_Tick(object sender, EventArgs e)
        {
            x += 20;
            var workingArea = Screen.GetWorkingArea(this);
            this.Location = new Point(workingArea.Right - this.x, workingArea.Bottom - Size.Height - 30);
            if (this.Location.X == workingArea.Right - this.Size.Width
                || this.Location.X < workingArea.Right - this.Size.Width)
            {
                this.Styler.Stop();
            }
        }

        private void RightSide_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}